package com.xl6667.util;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class BeanCopyUtil {
    public static <V>V copyBean(Object o,Class<V> clasz){
        V v = null;
        try {
            v = clasz.newInstance();
            BeanUtils.copyProperties(o,v);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return v;
    }
    public static <V,O>List<V> copyBeanList(List<O> oList,Class<V> clasz){
        return oList.stream()
                .map(o -> copyBean(o, clasz))
                .collect(Collectors.toList());
    }
}
